package com.lanswon.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lanswon.common.enums.ArticleStatus;
import com.lanswon.entity.ArticleVO;
import com.lanswon.service.AboutService;
import com.lanswon.service.ArticleService;

@Controller
@RequestMapping("/front/aboutus")
public class AboutUsController {
	@Autowired
	private ArticleService articleService;
	@Autowired
	private AboutService aboutService;

	@RequestMapping("index")
	public String index(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {

		return "/front/aboutus/index";
	}

	@RequestMapping("detail")
	@ResponseBody
	public Map<String, Object> aboutsmkDetail(HttpServletRequest request, HttpServletResponse response,
			@PathVariable("articleType") Integer articleType) {
		Map<String, Object> viewMap = new HashMap<>();
		try {
			Map<String, Object> accessMap = new HashMap<>();
			accessMap.put("articleType", articleType);
			accessMap.put("articleStatus", ArticleStatus.ARTICLE_STATUS_NOMAL.getCode());
			List<ArticleVO> pageList = articleService.findArticleByCondition(accessMap);
			viewMap.put("article", pageList != null && pageList.size() > 0 ? pageList.get(0) : null);
			viewMap.put("code", 0);
			viewMap.put("message", "查询成功");
			viewMap.put("articleType", articleType);
		} catch (Exception e) {
			e.printStackTrace();
			viewMap.put("code", 2);
			viewMap.put("message", "查询失败");
		}
		return viewMap;
	}

	@RequestMapping("show")
	@ResponseBody
	public Map<String, Object> showDetail(HttpServletRequest request, HttpServletResponse response) {
		return aboutService.showDetail();
	}
}
